<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/view/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
	
	<title>客户认筹1</title>
	<link href="${project}/ds/css/input.css" rel="stylesheet"/>
	<link href="${project}/ds/css/roomStyle.css" rel="stylesheet"/>
	<link href="${project}/ds/lib/layui/css/layui.css" rel="stylesheet"/>
	<link href="${project}/ds/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet"/>
	<link href="${project}/ds/lib/font-awesome-4.7.0/css/font-awesome.css" rel="stylesheet" />
	<link href="${project}/ds/lib/ligerUI/skins/Gray2014/css/all.css" rel="stylesheet"/>
	<link href="${project}/ds/css/popup.css" rel="stylesheet" />
	
	<script src="${project}/ds/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
	<script src="${project}/ds/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
	<script src="${project}/ds/lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
	<script src="${project}/ds/lib/jquery.form.js" type="text/javascript"></script>
	<script src="${project}/ds/js/XHD.js" type="text/javascript"></script>
	<script src="${project}/ds/js/base64.js" type="text/javascript"></script>
	<script src="${project}/ds/lib/layui/layui.js" type="text/javascript"></script>
	<script src="${project}/ds/js/js/ws.js" type="text/javascript"></script>
	<script src="${project}/ds/js/md5.js" type="text/javascript"></script>
	<script src="${project}/ds/js/pupop.js" type="text/javascript"></script>
	<script src="${project}/ds/js/websocked.js" type="text/javascript"></script>
	<script src="${project}/ds/js/room/curd.js" type="text/javascript"></script>
	<script src="${project}/ds/js/room/command.js" type="text/javascript"></script>
	<script src="${project}/ds/js/layeralert.js" type="text/javascript"></script>
<script type="text/javascript">
    var manager;
    var telexist = true;
    var clientexist = true;
    var clientid = -1;
    var layer;
    var layerwindow;
    var element;
    var loadindex = 0;

    layui.use(['upload', 'layer'],
        function () {
            var option1 = {
                elem: "#ImportFile1",
                title: "上传认筹客户",
                url: "/customerOne/uploadCustomerOne",
                method: "post",
                type: "file",
                success: function (result) {
                    console.log(result);
                    if (result.result === "false") {
                        layer.msg("上传格式不正确", { icon: 2 });
                    }
                    else {
                        var fileName = result.fileName;
                        var url = "/customerOne/uploadcustomerOnePreview?type=1&fileName=" + encodeURI(fileName);
                        OpenUpload1(url);
                        //wsuserload();
                    }
                }
            };
            layui.upload(option1);
            
            var option2 = {
                elem: "#ImportFile2",
                title: "上传管理客户",
                url: "/customerOne/uploadCustomerOne",
                method: "post",
                type: "file",
                success: function (result) {
                    console.log(result);
                    if (result.result === "false") {
                        layer.msg("上传格式不正确", { icon: 2 });
                    }
                    else {
                        var fileName = result.fileName;
                        var url = "/customerOne/uploadcustomerOnePreview?type=2&fileName=" + encodeURI(fileName);
                        OpenUpload2(url);
                        //wsuserload();
                    }
                }
            };
            layui.upload(option2);
            layer = layui.layer;
        });
    
    $(function() {
        //主购人数

 //       websocketConnect();
//        $("#form1").ligerForm();

        manager2 = $("#maingrid5")
            .ligerGrid({
                columns: [
                    {
                        display: '序号',
                        width: 50,
                        render: function (rowData, rowindex) {
                            return rowindex + 1;
                        }
                    },
                    {
                        display: '在线',
                        name: "D_Online",
                        width: 35,
                        render: function (item) {
                            var html = "<div style='margin-top:3px;'><input type='checkbox'  class='showmenu'";
                            if (item.D_Online > 0){
                            	html += "checked='checked'";
                            }
                            html += " disabled='disabled' /></div>";
                            return html;
                        }
                    },
                    {
                        display: "认购", name: "Seatcount", width: 35, render: function (item) {
                            var html = "<div style='margin-top:3px;'><input type='checkbox'  class='showmenu'";
                            if (item.Seatcount > 0){
                            	html += "checked='checked'";                           	
                            }
                            html += " disabled='disabled' /></div>";
                            return html;
                        }
                    },
                    {
                        display: "价格", name: "D_PriceType", width: 35,
                        render: function (rowdata) {
                            var html = "<div style='margin-top:3px;'><input type='checkbox'  class='showmenu'";
                            if (rowdata.D_PriceType > 0){ html += "checked='checked' ";}
                            html += " onchange='pricechange2()' /></div>";
                            return html;
                        }
                    },
                    {
                        display: "锁定", name: "D_Lock", width: 35, render: function (item) {
                            var html = "<div style='margin-top:3px;'><input type='checkbox'  class='showmenu'";
                            if (item.D_Lock > 0){ html += "checked='checked' "};
                            html += " onchange='lockchange2()' /></div>";
                            return html;
                        }
                    },
                    { display: "姓名", name: "D_Name", width: 60 },
                    { display: "性别", name: "D_Sex", width: 40 },
                    { display: "手机", name: "D_Tel", width: 110 },
                    { display: "身份证", name: "D_Card", width: 160 },
                    //{ display: "登录批次", name: "D_LoginId", width: 60 },
                    { display: "最后操作时间", format: "yyyy-MM-dd", name: "D_OpTime", width: 160 }
                ],
                dataAction: "server",
                sortName: "D_ID",
                sortOrder: "desc",
                pageSize: 50,
                rowHeight: 22,
                pageSizeOptions: [20, 30, 50, 100],
                url: "/customerOne/getGrid1",
                width: '100%',
                height: '100%',
                heightDiff: -1
            });

        manager1 = $("#maingrid4")
            .ligerGrid({
                columns: [
                    {
                        display: '序号',
                        width: 50,
                        render: function (rowData, rowindex) {
                            return rowindex + 1;
                        }
                    },
                    {
                        display: '在线',
                        name: "D_Online",
                        width: 35,
                        render: function (item) {
                            var html = "<div style='margin-top:3px;'><input type='checkbox'  class='showmenu'";
                            if (item.D_Online == true) html += "checked='checked' ";
                            html += " disabled='disabled' /></div>";
                            return html;
                        }
                    },
                    {
                        display: "认购", name: "Seatcount", width: 35, render: function (item) {
                            var html = "<div style='margin-top:3px;'><input type='checkbox'  class='showmenu'";
                            if (item.Seatcount > 0) html += "checked='checked' ";
                            html += " disabled='disabled' /></div>";
                            return html;
                        }
                    },
                    {
                        display: "锁定", name: "D_Lock", width: 35, render: function (item) {
                            var html = "<div style='margin-top:3px;'><input type='checkbox'  class='showmenu'";
                            if (item.D_Lock > 0) html += "checked='checked' ";
                            html += " onchange='lockchange1()' /></div>";
                            return html;
                        }
                    },
                    { display: "姓名", name: "D_Name", width: 60 },
                    { display: "性别", name: "D_Sex", width: 40 },
                    { display: "手机", name: "D_Tel", width: 110 },
                    { display: "身份证", name: "D_Card", width: 160 },
                    { display: "地址", name: "D_Address", width: 150 },
                    { display: "置业顾问", name: "D_Saller", width: 80 },
                    { display: "置业顾问手机", name: "D_SallerTel", width: 110 },
                    { display: "代理机构", name: "D_Proxy", width: 110 },
                    { display: "关联人", name: "D_GName", width: 60 },
                    { display: "关联人身份证", name: "D_GCardNo", width: 160 },
                    { display: "关联人手机", name: "D_GTel", width: 110 },
                    //{
                    //    display: "认筹数", name: "D_FromCount", width: 80,
                    //    render: function (rowdata) {
                    //        var html = "<a href='javascript:void(0);' ";
                    //        html += " onclick='ShowTipHelper(this," + rowdata["D_ID"] + ")'>";
                    //        html += rowdata["D_FromCount"];
                    //        html += "</a>";
                    //        return html;
                    //    }
                    //},
                    { display: "认筹类型", name: "D_FromType", width: 80 },
                    { display: "登录批次", name: "D_LoginId", width: 60 },
                    { display: "登记时间", format: "yyyy-MM-dd", name: "D_OperationDate", width: 160 },
                    { display: "最后操作时间", format: "yyyy-MM-dd HH:mm:ss", name: "D_lastLoginTime", width: 160 },
                    { display: "操作员", name: "D_OperationName", width: 80 }
                ],
                dataAction: "server",
                sortName: "D_ID",
                sortOrder: "desc",
                pageSize: 50,
                rowHeight: 22,
                pageSizeOptions: [20, 30, 50, 100],
                url: "/customerOne/getGrid2",
                width: '100%',
                height: '100%',
                heightDiff: -1
            });
        //刷卡
        //connectWB(); //连接websocket
        //initLayout();
        //$(window)
        //    .resize(function() {
        //        initLayout();
        //    });
    });

    

    //function ShowTipHelper(g, id) {
    //    $.ajax({
    //        url: "../data/Tuser.ashx",
    //        type: "post",
    //        async: false,
    //        data: { Action: "gethelper", parentid: id },
    //        dataType: "json",
    //        success: function (data) {
    //            var html = "";
    //            for (var i in data) {
    //                if (data.hasOwnProperty(i)) {
    //                    var help = data[i];
    //                    html += help.D_Name + "  手机：" + help.D_Tel + "<br/>";
    //                    html += "身份证：" + help.D_CardNo + "<br/>";
    //                }
    //            }
    //            if (html !== "") {
    //                layer.tips(html,
    //                    $(g),
    //                    {
    //                        tips: [2, "#3595CC"],
    //                        time: 2000
    //                    });
    //            } else {
    //                layer.tips("该客户没有关联人",
    //                    $(g),
    //                    {
    //                        tips: [2, "#3595CC"],
    //                        time: 1000
    //                    });
    //            }
    //        }
    //    });
    //}

    function OpenUpload1(url) {
        //url = urlencode(url);
        layer.open({
            type: 2,
            title: '认筹账号上传',
            shadeClose: true,
            area: ['1200px', '600px'],
            content: url
        });
    }

    function OpenUpload2(url) {
        //url = urlencode(url);
        layer.open({
            type: 2,
            title: '管理账号上传',    
            shadeClose: true,
            area: ['550px', '600px'],
            content: url
        });
    }

    function valitedClient(idCard) {
        if ($("#divexist").length > 0) {
            $("#divexist").remove();
        }
        $.ajax({
            url: "../data/Tuser.ashx",
            type: "post",
            async: false,
            data: { Action: "validate", card: idCard },
            dataType: "json",
            success: function(data) {
                var result = data.result;
                var json = {};
                if (data.json) {
                    json = data.json;
                    for (var n in json) {
                        if (json.hasOwnProperty(n)) {
                            if (json[n] === "null" || json[n] === null)
                                json[n] = "";
                        }
                    }
                }
                if (result === "false") {
                    showError(data.msg);
                } else if (result === "exist") {
                    showError(data.msg);
                    clientid = json.D_ID;
                    AddBuyer("main", $("#cname").val(), $("#ccard").val());
                    ShowHelper(clientid);
                } else if (result === "true") {
                    clientexist = false;
                    clientid = -1;
                }
            }
        });
    }

    //加载关联人
    function ShowHelper(id) {
        $.ajax({
            url: "../data/Tuser.ashx",
            type: "post",
            async: false,
            data: { Action: "gethelper", parentid: id },
            dataType: "json",
            success: function(data) {
                for (var i in data) {
                    if (data.hasOwnProperty(i)) {
                        var help = data[i];
                        AddBuyer("help", help.D_Name, help.D_CardNo + "   手机：" + help.D_Tel);
                    }
                }
            }
        });
    }

    function showError(msg) {
        var exist = $("<div></div>");
        exist.attr("id", "divexist");
        exist.css("position", "absolute");
        exist.css("top", "70px");
        exist.css("left", "180px");
        exist.css("color", "red");
        exist.html(msg);
        $("body").append(exist);
    }

    function validateTel(tel) {
        if ($("#divexist").length > 0) {
            $("#divexist").remove();
        }
        $.ajax({
            url: "../data/Tuser.ashx",
            type: "post",
            data: { Action: "validateTel", tel: tel },
            dataType: "json",
            success: function(data) {
                var result = data.result;
                if (result === "false") {
                    showError(data.msg);
                } else if (result === "true") {
                    telexist = false;
                }
            }
        });
    }

    function openfile1() {

        $("#ImportFile1").click();
    }
    function openfile2() {
        $("#ImportFile2").click();
    }

    function SaveClientInformation() {
        loadindex = layload("保存中");
        var issave = getissave();
        if (issave) {
            $.ajax({
                url: "../data/Tuser.ashx",
                type: "post",
                data: issave,
                dataType: "json",
                success: function(result) {
                    if (result.result === "true") {
                        wsuseradd(user, $("#phone").val());
                    } else if (result.result === "false") {
                        closewait();
                        clientid = 0;
                        top.$.ligerDialog.warn(result.msg);
                    }
                }
            });
        }
    }

    //发送新增消息
    function wsuseradd(user, tel) {
        var json = wsorder.useradd(user, tel);
        websocket.send(JSON.stringify(json));
    }

    //发送删除消息
    function wsuserdel(user, tel) {
        var json = wsorder.userdel(user, tel);
        websocket.send(JSON.stringify(json));
    }

    //发送显示价格消息
    function changeShowPrice(state, tel) {
    	$.ajax({
            url: "/customerOne/changeShowPrice",
            type: "post",
            async: true,
            data: { state: state, tel: tel },  
            dataType: "json",
            success: function(data) {
                layer.msg(data.msg);
            }
        });
    }

   

    //发送用户锁定消息
    function changeUserLock(state, tel) {
    	$.ajax({
            url: "/customerOne/changeUserLock",
            type: "post",
            async: true,
            data: { state: state, tel: tel },  
            dataType: "json",
            success: function(data) {
            	if(state==1){
            		userGetOut(tel);
            	}else{
                	layer.msg(data.msg);           		
            	}
            }
        });
    }
	
    
    //发送用户踢出消息
    function userGetOut(tel) {
    	 $.ajax({
             url: "/customerOne/userGetOut",
             type: "post",
             async: true,
             data: { tel: tel},  
             dataType: "json",
             success: function(data) {
                 layer.msg(data.msg);
             }
         });
    }

    //发送全删消息
    function wsuseralldel(user) {
        var json = wsorder.useralldel(user);
        websocket.send(JSON.stringify(json));
    }

    //发送载入消息
    function wsuserload() {
        var json = wsorder.loadusers(user);
        websocket.send(JSON.stringify(json));
    }

    //ws新增成功回复
    function wsuseraddreply() {
        f_reload();
        closewait();
    }

    //ws删除成功回复
    function wsuserdelreply() {
        manager1.loadData(true);
        manager2.loadData(true);
        closewait();
    }

    //ws加载成功回复
    function wsuserloadreply() {
        manager1.loadData(true);
        manager2.loadData(true);
        closewait();
    }

    //ws加载成功回复
    function wsuserupdatereply() {
        manager1.loadData(true);
        manager2.loadData(true);
        layer.close(layerwindow);
    }

    //修改用户信息
    function mobileuserupdate() {
        var json = wsorder.mobileuserupdate(user, tels, param);
        websocket.send(JSON.stringify(json));
    }

    //修改用户
    function update1() {
        var row = manager1.getSelectedRow();
        if (row) {
            $('#D_Tel').val("");
            layerwindow = layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area: ['500px', '200px'],
                skin: 'layui-layer-lan', //没有背景色
                shadeClose: true,
                content: $('#userdiv1')
            });
        } else {
            layer.msg("请选择行");
        }
    }

    //修改用户
    function update2() {
        var row = manager2.getSelectedRow();
        if (row) {
            $('#D_LoginId2').val("");
            layerwindow = layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area: ['500px', '200px'],
                skin: 'layui-layer-lan', //没有背景色
                shadeClose: true,
                content: $('#userdiv2')
            });
        } else {
        	layer.msg("请选择行");
        }
    }
    
    function save1() {
        if ($("#D_Tel").val() == "") {
            layer.msg("请填写手机号");
            return;
        }
        var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
        if (!myreg.test($("#D_Tel").val())) {
        	layer.msg("请填写正确的手机号");
            return;
        }else {
            var row = manager1.getSelectedRow();
            var tel = row.D_Tel;
            var newTel = $("#D_Tel").val();
            var tels = {'tel':tel,"newTel":newTel};
            var paramjson = JSON.stringify(tels);
            console.log(paramjson);
            loadindex = layload("客户变更中");
            $.ajax({
                url: "/customerOne/updateCustomerOne",
                type: "post",
                async: true,
                data: { json: paramjson},
                dataType: "json",
                success: function(data) {
                    	layer.close(loadindex);
                   	    layer.close(layerwindow);
                    if(data.result==="true"){
                    	layer.msg(data.msg);
                    	 f_reload();
                    }else{
                    	layer.msg(data.msg);
                    }
                }
            });
        }
    }
    
    function save2() {
    	 if ($("#D_Tel2").val() == "") {
             layer.msg("请填写手机号");
             return;
         }
         var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
         if (!myreg.test($("#D_Tel2").val())) {
         	layer.msg("请填写正确的手机号");
             return;
         }else {
             var row = manager2.getSelectedRow();
             var tel = row.D_Tel;
             var newTel = $("#D_Tel2").val();
             var tels = {'tel':tel,"newTel":newTel};
             var paramjson = JSON.stringify(tels);
             console.log(paramjson);
             loadindex = layload("客户变更中");
             $.ajax({
                 url: "/customerOne/updateCustomerOne2",
                 type: "post",
                 async: true,
                 data: { json: paramjson},
                 dataType: "json",
                 success: function(data) {
                     if(data.result==="true"){
                     	layer.msg("变更成功");
                     	layer.close(loadindex);
                     	 f_reload();
                     	 layer.close(layerwindow);
                     }
                 }
             });
         }
    }

    function closewait() {
        layer.close(loadindex);
    }

    function AddBuyer(level, name, cardno) {
        //新增购买人
        $("#tree1").ligerGetTreeManager().selectNode(level);
        var a = $("#tree1").ligerGetTreeManager().getSelected();
        $("#tree1")
            .ligerGetTreeManager()
            .append(a.target,
                [
                    {
                        id: level + 'buy',
                        d_icon: '../images/icon/37.png',
                        text: name + "  身份证：" + cardno
                    }
                ]);
    }

    //查询
    
    //下载客户导入模版
    function LoadModel() {
        var form = $("<form>"); //定义一个form表单
        form.attr("style", "display:none");
        form.attr("target", "");
        form.attr("method", "post");
        form.attr("action", "../data/Room.ashx");

        var input1 = $("<input>");
        input1.attr("type", "hidden");
        input1.attr("name", "Action");
        input1.attr("value", "loadFile");

        var input2 = $("<input>");
        input2.attr("type", "hidden");
        input2.attr("name", "type");
        input2.attr("value", "client");

        $("body").append(form); //将表单放置在web中
        form.append(input1);
        form.append(input2);
        form.submit(); //表单提交
    }


	//导出
    function Load0() {
    	 window.location="/customerOne/downloadCustomerOne?type=0";
    }
	//导出
    function Load1() {
    	 window.location="/customerOne/downloadCustomerOne?type=1";
    }
    

    function del1() {
        var row = manager1.getSelectedRow();
        if (row) {
            layer.confirm('是否确认删除客户？'
                , function (index) {
                    layer.close(index);
                    var tel = row.D_Tel;
                    delUser(tel);
                    loadindex = layload("客户删除中");
                });
        } else {
        	layer.msg("请选择行");
        }
    }

    function del2() {
        var row = manager2.getSelectedRow();
        if (row) {
            layer.confirm('是否确认删除客户？'
                , function (index) {
                    layer.close(index);
                    var tel = row.D_Tel;
                    delUser(tel);
                    loadindex = layload("客户删除中");
                });
        } else {
        	layer.msg("请选择行");
        }
    }
	function delUser(tel){
		 $.ajax({
             url: "/customerOne/deleteCustomerOne",
             type: "post",
             data: "tel="+tel,
             dataType: "json",
             success: function(result) {
                	 layer.close(loadindex);
                	 f_reload();
                
                   layer.msg(result.msg);
                 
             }
         });
	}
	
	function delAllUser(source){
		 $.ajax({
             url: "/customerOne/deleteCustomerOneAll",
             type: "post",
             data: "source="+source,
             dataType: "json",
             success: function(result) {
                 if (result.result === "true") {
                	 layer.close(loadindex);
                	 f_reload();
                   layer.msg("删除成功");
                 }
             }
         });
	}
	
	  function alldel(source) {
	        layer.confirm('是否确认删除所有客户？请慎重考虑'
	            , function (index) {
	                layer.close(index);
	                delAllUser(source);
	                loadindex = layload("客户删除中");
	            });
	    }
    function pricechange1() {

        var row = manager1.getSelectedRow();
        if (row) {
            if (row.D_PriceType == 1) {
                row.D_PriceType = 0;
                var tel = row.D_Tel;
                wsuserunshowprice(user, tel);
            }
            else {
                row.D_PriceType = 1;
                var tel = row.D_Tel;
                wsusershowprice(user, tel);
            }
        } else {
            top.$.ligerDialog.warn("请选择行");
        }
    }
	
    //价格修改
    function pricechange2() {
        var row = manager2.getSelectedRow();
        if (row) {
            if (row.D_PriceType == 1) {//关闭价格显示
                row.D_PriceType = 0;
                var tel = row.D_Tel;
                changeShowPrice(0, tel);
            }
            else {//打开价格显示
                row.D_PriceType = 1;
                var tel = row.D_Tel;
                changeShowPrice(1, tel);
            }
        } else {
        	layer.msg("请选择行");
        }
    }

    function lockchange1() {

        var row = manager1.getSelectedRow();
        if (row) {
            if (row.D_Lock == 0) {
                row.D_Lock = 1;
                var tel = row.D_Tel;
                changeUserLock(1, tel);
            }
            else {
                row.D_Lock = 0;
                var tel = row.D_Tel;
                changeUserLock(0, tel);
            }
        } else {
           layer.msg("请选择行");
        }
    }

    function lockchange2() {

        var row = manager2.getSelectedRow();
        if (row) {
            if (row.D_Lock == 0) {
                row.D_Lock = 1;
                var tel = row.D_Tel;
                changeUserLock(1, tel);
            }
            else {
                row.D_Lock = 0;
                var tel = row.D_Tel;
                changeUserLock(0, tel);
            }
        } else {
           layer.msg("请选择行");
        }
    }

    function ShowPrice2() {
        var row = manager2.getSelectedRow();
        if (row) {
            layer.confirm('是否确认让该客户显示价格？'
                , function (index) {
                    layer.close(index);
                    var tel = row.D_Tel;
                    wsusershowprice(user, tel);
                });
        } else {
            top.$.ligerDialog.warn("请选择行");
        }
    }

    function UnShowPrice2() {
        var row = manager2.getSelectedRow();
        if (row) {
            layer.confirm('是否确认让该客户隐藏价格？'
                , function (index) {
                    layer.close(index);
                    var tel = row.D_Tel;
                    wsuserunshowprice(user, tel);
                });
        } else {
            top.$.ligerDialog.warn("请选择行");
        }
    }

  
    

    function getissave() {
        var birthday = $("#cborn").text().replace('年', '-').replace('月', '-').replace('日', '');
        var result = {
            Action: "save",
            cname: $.trim($("#cname").val()),
            ccard: $("#ccard").val(),
            csex: $(".csex:checked").val(),
            cborn: birthday,
            cadd: $.trim($("#cadd").text()),
            tel: $.trim($("#phone").val()),
            sallid: $("#sallid").val() === "" ? "0" : $("#sallid").val(),
            D_FormCount: $("#D_FormCount").text().indexOf("请选择") !== -1 ? "1" : $("#D_FormCount").text(),
            D_FromType: $("#D_FromType").text().indexOf("请选择") !== -1 ? "" : $("#D_FromType").text()
        };
        return result;
    }

    function f_reload() {
        manager1.loadData(true);
        manager2.loadData(true);
        //resetdata();

        if ($("#divexist").length > 0) {
            $("#divexist").remove();
        }
    };

    function UserSave(userdata, index, source) {
        console.log("usersave");
        layer.close(waitindex);
        var load = layer.load(1, { time: 10000 });
        $.ajax({
            url: "/customerOne/addGrid",
            type: "post",
            data: { json: userdata, source: source },
            dataType:"json",
            success: function (data) {
            	console.log(data);
            	console.log(data.result);
                if (data.result === "true") {
                    console.log("true");
                    layer.msg("提交成功！");
                    layer.close(load);

                    f_reload();
                    layer.close(index);
                }
            }
        });
    }



    function openadd() {
        $("#cname").val("");
        $("#phone").val("");
        $("#ccard").val("");
        $("#D_FromType").val("");
        layer.close();
        layerwindow = layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: '300px',
            skin: 'layui-layer-lan', //没有背景色
            shadeClose: true,
            content: $('#adddiv')
        });
    }

    //发送新增消息
    function addsave() {
        var param = {
            D_Tel:$("#phone").val(),
            D_Name:$("#cname").val(),
            D_Card:$("#ccard").val(),
            D_FromType: $("#D_FromType").val(),
            D_Sex: "男",
            D_Source:1
        };
        var paramjson = JSON.stringify(param);
        console.log(paramjson);
        loadindex = layload("客户新增中");
        $.ajax({
            url: "/customerOne/saveCustomerOne",
            type: "post",
            async: true,
            data: { json: paramjson},
            dataType: "json",
            success: function(data) {
                if(data.result==="true"){
                	layer.msg("新增成功");
                	layer.close(loadindex);
                	 f_reload();
                	layer.close(layerwindow);
                }
            }
        });
    }

    
    
</script>
<style type="text/css">
    form{height:auto; width:auto;}
</style>
</head>
<body>
<div class="clearfix" style="width:100%; height:100%;">
    <div id="toolbar" style="padding:10px;">
        <div style="width:39%;float:left">
            <div class="layui-inline" style="font-size:22px">管理账号</div>
            <div class="layui-btn" onclick="Load1()">导出</div>
                <div class="layui-inline">
                    <div class="layui-btn" onclick="openfile2()">导入</div>
                </div>
            <div class="layui-inline">
                <div class="layui-btn" onclick="del2()">删除</div>
            </div>
            <div class="layui-inline">
                <div class="layui-btn" onclick="openadd()">新增</div>
            </div>
            <div class="layui-btn-group">
                <div class="layui-btn" onclick="update2()">修改</div>
            </div>
            <div class="layui-inline" style="display:none">
                <input type="file" id="ImportFile2" name="customerOne" lay-ext="xls|xlsx" class="layui-upload-file"/>
            </div>
            <div class="layui-btn-group" style="float:right">
                <div class="layui-btn layui-btn-danger" onclick="alldel(1)">全删</div>
            </div>
        </div>
        <div style="width:59%;float:right">
            <div class="layui-inline" style="font-size:22px">认筹账号</div>
            <div class="layui-btn" onclick="Load0()">导出</div>
                <div class="layui-inline">
                    <div class="layui-btn" onclick="openfile1()">导入</div>
                </div>
            <div class="layui-inline">
                <div class="layui-btn" onclick="del1()">删除</div>
            </div>
            <div class="layui-btn-group">
                <div class="layui-btn" onclick="update1(0)">修改</div>
            </div>
            <div class="layui-inline" style="display:none">
                <input type="file" id="ImportFile1" name="customerOne" lay-ext="xls|xlsx" class="layui-upload-file"/>
            </div>
            <div class="layui-btn-group" style="float:right">
                <div class="layui-btn layui-btn-danger" onclick="alldel()">全删</div>
            </div>
        </div>
        
    </div>
    <div style="height: 100%; width: 100%;">
        <div style="left: 0px; width:39%; height: 100%; position: fixed; top:50px;">
            <div id="maingrid5" style="margin: -1px;"></div>
        </div>
        <div style="left: 41%; width:59%; height: 100%; position: fixed; top:50px;">
            <div id="maingrid4" style="margin: -1px;"></div>
        </div>
    </div>
</div>
<div id="sallerdiv" style="display:none; text-align: center; padding:10px;">
</div>
<div id="formcountdiv" style="display:none; text-align: center; padding:10px;">
</div>

<div id="formtypediv" style="display:none; text-align: center; padding:10px;">
</div>
    
    <div id="userdiv1" style="width: 480px; display:none; margin-right:20px">
        <div id="bantype1" style="width:150px; margin-top:10px;margin-bottom:10px;padding-left:175px;font-size:24px">
            修改用户信息
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="number" id="D_Tel" name="D_Tel" required lay-verify="required" placeholder="手机号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div style="width: 100px; margin-left:218px;">
            <div class="layui-form-item">
                <div class="layui-btn" onclick="save1()">确认</div>
            </div>
        </div>
    </div>
    
    <div id="userdiv2" style="width: 480px; display:none; margin-right:20px">
        <div id="bantype2" style="width:150px; margin-top:10px;margin-bottom:10px;padding-left:175px;font-size:24px">
            修改用户信息
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="number" id="D_Tel2" name="D_Tel2" required lay-verify="required" placeholder="手机号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div style="width: 100px; margin-left:218px;">
            <div class="layui-form-item">
                <div class="layui-btn" onclick="save2()">确认</div>
            </div>
        </div>
    </div>

    

    <div style="width: 300px; display:none; " id="adddiv" class="layui-form">
        <div style="width:160px; margin-top:10px;margin-bottom:10px;padding-left:70px;font-size:24px">
            添加管理账号
        </div>
      <!--   <div style="width:100%;" > -->
            <div class="layui-form-item">
                <label class="layui-form-label" style="width:50px">姓名</label>
                <div class="layui-input-block">
                    <input class="layui-input" style="width: 150px;" type="text" onchange="javascript:if(!/^[\u4e00-\u9fa5]+$/gi.test(this.value))alert('姓名只能是汉字');" id="cname" name="cname" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width:50px">手机</label>
                <div class="layui-input-block">
                    <input class="layui-input" style="width: 150px;" type="text" id="phone" name="phone" onkeyup="value = value.replace(/[^\d]/g, '')" maxlength="11"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width:50px">身份证</label>
                <div class="layui-input-block">
                    <input class="layui-input" style="width: 150px;" type="text" id="ccard" name="ccard" maxlength="18"/>
                </div>
            </div>
           
            <div class="layui-form-item">
                <label class="layui-form-label" style="width:50px">认筹类型</label>
                <div class="layui-input-block">
                	<select name="D_FromType"  id="D_FromType" style="width: 150px;display:block;">
						<c:forEach var="item"   items="${renchous}">
							<option value="${item.money}">${item.money}</option>
						</c:forEach>						
					</select>
                </div>
            </div>
        <!-- </div> -->
        <div style="width: 100%; margin-left:104px auto;">
                <div class="layui-form-item">
                <div class="layui-input-block">
                    <div id="Div2" class="layui-btn" onclick="addsave()">确认添加</div>
                </div>
                </div>
        </div>
    </div>
</body>
</html>